package com.mb.app.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.domain.TbAppChannelConfig;
import com.mb.app.dao.TbAppChannelConfigMapper;
import com.mb.app.domain.TbAppChannelConfig;
import com.mb.app.service.ITbAppChannelConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 应用渠道配置信息  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-03-21
 */
@Service
@Slf4j
public class TbAppChannelConfigServiceImpl extends ServiceImpl<TbAppChannelConfigMapper, TbAppChannelConfig> implements ITbAppChannelConfigService {


    @Override
    public List<TbAppChannelConfig> queryList(Map<String, Object> map) {
        List<TbAppChannelConfig> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }

    @Override
    public int save(TbAppChannelConfig TbAppChannelConfig) {
        TbAppChannelConfig.setCreateTime(new Date());
        return this.baseMapper.insert(TbAppChannelConfig);
    }

    @Override
    public int update(TbAppChannelConfig TbAppChannelConfig) {
        try {
            TbAppChannelConfig TbAppChannelConfig1 = new TbAppChannelConfig();
            TbAppChannelConfig1.setAppChannelId(TbAppChannelConfig.getAppChannelId());
            TbAppChannelConfig1.setDataStatus(1);
            TbAppChannelConfig TbAppChannelConfigDO = this.baseMapper.selectOne(TbAppChannelConfig1);
            if(TbAppChannelConfigDO != null){
                TbAppChannelConfig.setUpdateTime(new Date());
                this.baseMapper.updateById(TbAppChannelConfig);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }



    @Override
    public int remove(Long appchannelId) {
//        return this.baseMapper.deleteById(appId);
        TbAppChannelConfig TbAppChannelConfig = new TbAppChannelConfig();
        TbAppChannelConfig.setAppChannelId(appchannelId);
        TbAppChannelConfig.setDataStatus(0);
        return this.baseMapper.updateById(TbAppChannelConfig);
    }

    @Override
    public TbAppChannelConfig getDtl(Long appchannelId) {
        TbAppChannelConfig TbAppChannelConfig = new TbAppChannelConfig();
        TbAppChannelConfig.setAppChannelId(appchannelId);
        TbAppChannelConfig.setDataStatus(1);
        return this.baseMapper.selectOne(TbAppChannelConfig);
    }

    @Override
    public boolean channelNameCodeExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByChannelInfo(params).size() > 0;
        return exit;
    }


}
